package com.itheima.schedule;

import com.itheima.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <h1>信息点赞数定时器（从redis同步到数据库）</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/12/14
 */
@Component
@Slf4j
public class LikeSchedule {
    @Resource
    private MessageService messageService;

    /**
     * 同步redis点赞数到数据库
     */
//    @Scheduled(fixedDelay = 5 * 60 * 1000)
    @Scheduled(cron = "0 0 8 * * ?")
    public void syncLikeMessage() {
        messageService.syncLikeMessage();
        log.info("信息点赞数定时器，同步成功:"+ LocalDateTime.now());
    }

    /**
     * redis信息历史点赞数更新
     */
    @Scheduled(cron = "0 0 8 * * ?")
    public void refreshHistoryCount(){
        messageService.refreshHistoryCount();
        log.info("信息历史点赞数定时器，同步成功："+LocalDateTime.now());
    }
}
